package com.qding.park.manager.service.core.facade.impl.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qding.park.common.core.constant.CacheKeyThree;
import com.qding.park.common.core.exceptions.business.adapter.AdapterException;
import com.qding.park.common.core.exceptions.business.manager.adapterfactory.AdapterProxyCreateFail;
import com.qding.park.common.core.exceptions.business.manager.service.ServiceCoreException;
import com.qding.park.common.core.redis.JedisClient;
import com.qding.park.common.core.redis.SerializeUtils;
import com.qding.park.manager.common.pojo.ParkDataResult;
import com.qding.park.manager.facade.core.service.common.InviteCommonFacade;
import com.qding.park.manager.pojo.TbInvitecard;
import com.qding.park.manager.service.core.biz.InviteBiz;
import com.qding.park.manager.service.core.mapper.TbInvitecardMapper;
import com.qding.park.manager.service.core.mapper.TbParkspaceMapper;

@Service("inviteCommonFacade")
public class InviteCommonFacadeImpl implements InviteCommonFacade {
    private static final Logger _log = LoggerFactory.getLogger(InviteCommonFacadeImpl.class);
    @Autowired
    private InviteBiz inviteBiz;

    @Autowired
    private JedisClient jedisClient;
    
    @Autowired
    private TbInvitecardMapper tbInvitecardMapper;
    
    @Autowired
    private TbParkspaceMapper tbParkspaceMapper;
    

    @Override
    public ParkDataResult createInvite(TbInvitecard tbInvitecard) throws AdapterProxyCreateFail, AdapterException, ServiceCoreException {

        String id = inviteBiz.createInvite(tbInvitecard);
        
        _log.info("创建了邀请单::" + id);
        /*********** 加入监控列表 ***************************/
        String hkey = CacheKeyThree.MONITOR_INVITE_KEY;
        String value = SerializeUtils.serialize(tbInvitecard);
        String key = String.valueOf(tbInvitecard.getId());
        jedisClient.hset(hkey, key, value);
        /*********** 加入监控列表 ***************************/
        return ParkDataResult.createEmpty();
    }

    @Override
    public ParkDataResult cancelInvite(String orderId) throws ServiceCoreException, AdapterProxyCreateFail, AdapterException {

        inviteBiz.cancelInvite(orderId);
        
        /*********** 从监控列表中删除 ***************************/
        String hkey = CacheKeyThree.MONITOR_INVITE_KEY;
        String key = String.valueOf(orderId);
        jedisClient.hdel(hkey, key);
        /*********** 从监控列表 中删除 ***************************/
        
        return ParkDataResult.createEmpty();
    }

}
